// pages/charmdetail/charmdetail.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    charmNum: 1, //类型id/类型下标+1
    charmList: [], //明细列表
    charmtopList: ["收入记录", "提现记录", "兑换记录"], //类型列表
    charmpage: 1, //页数
    income: '', //我的积分
    active: 0,
  },
  //兑换
  toex() {
    this.setData({
      active: 0
    })
    wx.navigateTo({
      url: '/pages/exchange/exchange',
    })
  },
  //提现
  totx() {
    this.setData({
      active: 1
    })
    wx.navigateTo({
      url: '/pages/withdraw/withdraw',
    })
  },
  //切换类型
  charmNumChange(data) {
    // console.log(data)
    this.setData({
      charmNum: data.currentTarget.dataset.index + 1,
      charmList: [],
      charmpage: 1
    })
    this.getcharm()
  },
  // 获取列表
  getcharm() {
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&type=" +
      this.data.charmNum +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&page=" +
      this.data.charmpage +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      page: this.data.charmpage,
      type: this.data.charmNum,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/user/wages",
      data: params
    }).then((res) => {
      console.log(res.data.result),
        this.setData({
          income: res.data.result.income,
          charmList: this.data.charmList.concat(res.data.result.flowFormList),
        })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      charmList:[]
    })
    this.getcharm()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      charmList:[]
    })
    this.getcharm()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      charmpage: this.data.charmpage + 1
    })
    this.getcharm()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})